package me.snowiest.snowdrift.os.controller;

import com.tencent.cloud.CosStsClient;
import com.tencent.cloud.Response;
import com.tencent.cloud.cos.util.Jackson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.TreeMap;

@CrossOrigin
@RestController
@RequestMapping("/credential")
public class OSController {
    @Autowired
    private TreeMap<String, Object> credentialConfig;

    @GetMapping
    public String get() {
        Response credential = null;
        try {
            credential = CosStsClient.getCredential(credentialConfig);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Jackson.toJsonPrettyString(credential);
    }
}
